import request from '@/utils/api'

export const createTag = (tagData) => {
  return request.post('api/tags', tagData)
}

export const updateTag = (id, tagData) => {
  return request.put(`api/tags/${id}`, tagData)
}

export const deleteTag = (id) => {
  return request.delete(`api/tags/${id}`)
}

export const getTagById = (id) => {
  return request.get(`api/tags/${id}`)
}

export const getAllTags = () => {
  return request.get('api/tags', {
    headers: {
      'Cache-Control': 'no-cache'
    }
  })
}

export const addTagToNote = (noteId, tagId) => {
  return request.post('api/note-tags', null, {
    params: { noteId, tagId }
  })
}

export const removeTagFromNote = (noteId, tagId) => {
  return request.delete('api/note-tags', {
    params: { noteId, tagId }
  })
}

export const removeAllTagsFromNote = (noteId) => {
  return request.delete(`api/note-tags/note/${noteId}`)
}

export const removeTagFromAllNotes = (tagId) => {
  return request.delete(`api/note-tags/tag/${tagId}`)
}

export const getTagsByNoteId = (noteId) => {
  return request.get(`api/note-tags/note/${noteId}/tags`, {
    headers: {
      'Cache-Control': 'no-cache'
    }
  })
}

export const getNotesByTagId = (tagId) => {
  return request.get(`api/note-tags/tag/${tagId}/notes`, {
    headers: {
      'Cache-Control': 'no-cache'
    }
  })
}

export const isTagAttachedToNote = (noteId, tagId) => {
  return request.get('api/note-tags/exists', {
    params: { noteId, tagId },
    headers: {
      'Cache-Control': 'no-cache'
    }
  })
}